package cs2114.antiFingerMines;

/**
 * This class describes a mine's location and radius. It includes helper
 * methods to calculate distances
 *
 *  @author Blake Whaley
 *  @author Graham McLaughlin (gjm1324)
 *  @author William Vuong (wnvuong)
 *  @version Apr 9, 2012
 *
 */
public class Mine {

    private float xLocation;
    private float yLocation;
    private float radius;

    /**
     * This is the constructor, it is the only way to set x, y, and r
     * @param x the x location on the screen
     * @param y the y location on the screen
     * @param r the blast radius of the mine
     */
    public Mine(float x, float y, float r)
    {
        xLocation = x;
        yLocation = y;
        radius = r;
    }

    /**
     * get the x coordinate of the mine on the screen
     * @return the x coordinate
     */
    public float getX()
    {
        return xLocation;
    }

    /**
     * get the y coordinate of the mine on the screen
     * @return the y coordinate
     */
    public float getY()
    {
        return yLocation;
    }

    /**
     * get the blast radius of the mine if a finger gets closer than this
     * radius...BOOM!
     * @return the blasting radius
     */
    public float getRadius()
    {
        return radius;
    }

    /**
     * calculates the distance between the given (x,y) coordinates and the
     * location of the Mine
     * @param x the x coordinate
     * @param y the y coordinate
     * @return the distance
     */
    @SuppressWarnings("cast")
    public float distanceFrom(float x, float y)
    {
        //Pythagorean Theorem
        return (float)Math.sqrt(Math.pow((double)(x-xLocation), 2) +
                Math.pow((double)(y-yLocation), 2));
    }

    /**
     * calculates the distance between this mine and the given mine.
     * @param mine the other mine
     * @return the distance between them
     */
    public float distanceFrom(Mine mine)
    {
        //Utilizes the overloaded distanceFrom method
        return distanceFrom(mine.getX(), mine.getY());
    }

    // ----------------------------------------------------------
    /**
     * This is the same as the other distance from method except it takes a
     * finger of location type to calculate the distance from the finger to the
     * mine
     * @param finger is the location of the finger
     * @return the distance between the finger and the mine
     */
    public float distanceFrom(Location finger)
    {
        return distanceFrom(finger.getXloc(), finger.getYloc());
    }

    /**
     * calculates the distance between the blast radiuses between which the
     * finger can travel. This my be useful when we are setting up the field
     * and want a minimum distance between mines.
     * @param mine the other mine
     * @return the traversable distance between the two mines
     */
    public float traversableDistanceBetween(Mine mine)
    {
        return distanceFrom(mine) - radius - mine.getRadius();
    }

    // ----------------------------------------------------------
    /**
     * This is the same as a the other traversabledistance method except
     * it calculates the distance from the finger of location type to the mine
     * @param finger is the location of the finger
     * @return the traversable distance between the finger and the mine
     */
    public float traversableDistanceBetween(Location finger)
    {
        return distanceFrom(finger) - radius - 15;
    }

    /**
     * calculates the distance between the point (most likely the location of
     * the finger) and the mine
     * @param x the x coordinate
     * @param y the y coordinate
     * @return the distance from the blasting radius
     */
    public float distanceFromBlast(float x, float y)
    {
        return distanceFrom(x,y) - radius;
    }
}
